package com.manage.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manage.platform.dto.IndicatorSystemTaskDto;
import com.manage.platform.entity.IndicatorSystemTaskEntity;
import com.manage.platform.mapper.IndicatorSystemTaskMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * YWD
 * 2025/11/20
 */
@AllArgsConstructor
@Service
public class IndicatorSystemTaskServiceImpl extends ServiceImpl<IndicatorSystemTaskMapper, IndicatorSystemTaskEntity> {


    public Boolean linkTask(IndicatorSystemTaskDto dto) {
        //先删除再新增
        removeByIndicatorSystemId(dto.getId());
        List<IndicatorSystemTaskEntity> list = dto.getTaskId().stream().map(it -> {
            IndicatorSystemTaskEntity indicatorSystemTaskEntity = new IndicatorSystemTaskEntity();
            indicatorSystemTaskEntity.setTaskId(it);
            indicatorSystemTaskEntity.setIndicatorSystemId(dto.getId());
            return indicatorSystemTaskEntity;
        }).toList();
        return saveBatch(list);
    }

    public Boolean removeByIndicatorSystemId(Long indicatorSystemId) {
        LambdaQueryWrapper<IndicatorSystemTaskEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IndicatorSystemTaskEntity::getIndicatorSystemId, indicatorSystemId);
        return this.remove(queryWrapper);
    }


}
